﻿/*
 * Created by SharpDevelop.
 * User: xieen
 * Date: 2013-08-26
 * Time: 11:38
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace GoF23Learning._18.Memento_Pattern.Refactor
{
	/// <summary>
	/// Description of Memento.
	/// </summary>
	public class Memento
	{
		MemoryStream ms = new MemoryStream();
		
		internal   void SetState(object obj)
		{
			BinaryFormatter bf = new BinaryFormatter();
			
			bf.Serialize(ms,obj);		
 		
		}
		internal object SetState(object sender,EventArgs args)
		{					
			BinaryFormatter bf = new BinaryFormatter();
			ms.Seek(0,SeekOrigin.Begin);
			object obj =  bf.Deserialize(ms);	
			
			return obj;
			
		}
	}
}
